class DKJasonMacheteProj extends ROBallisticProjectile;

#exec OBJ LOAD FILE=WeaponSounds.uax
#exec OBJ LOAD FILE=ProjectileSounds.uax
#exec obj load file="msmon_01.u"

var vector Dir;
var bool bRing,bHitWater,bWaterStart;

// Physics
var() 		float 		StraightFlightTime;          // How long the projectile and flies straight
var 		float 		TotalFlightTime;             // How long the rocket has been in flight
var 		bool 		bOutOfPropellant;            // Projectile is out of propellant
// Physics debugging
var 		vector 		OuttaPropLocation;

var bool bActive;
var KFHumanPawn StuckTo;
var float ReduceSpeedTo,SlowDuration;

replication
{
	reliable if ( Role == ROLE_Authority )
		bActive;
}

simulated function PostNetReceive();

simulated function HitWall(vector HitNormal, actor Wall)
{
    if( Instigator != none )
    {
        OrigLoc = Instigator.Location;
    }
	Deactivate(none);
}

simulated function Explode(vector HitLocation, vector HitNormal);
simulated function Disintegrate(vector HitLocation, vector HitNormal);

simulated function PostBeginPlay()
{
    BCInverse = 1 / BallisticCoefficient;

    OrigLoc = Location;

    Dir = vector(Rotation);
    Velocity = speed * Dir;

    if (PhysicsVolume.bWaterVolume)
    {
        bHitWater = True;
        Velocity=0.6*Velocity;
    }
    super(Projectile).PostBeginPlay();
	
	LoopAnim('FlyMachete',1.0);
	bActive = true;
	Damage = DKJason(Instigator).RangedDamage;
	MyDamageType = DKJason(Instigator).RangedDamageType;
}

function TakeDamage( int Damage, Pawn InstigatedBy, Vector Hitlocation, Vector Momentum, class<DamageType> damageType, optional int HitIndex);
simulated function HurtRadius( float DamageAmount, float DamageRadius, class<DamageType> DamageType, float Momentum, vector HitLocation );

simulated function ProcessTouch(Actor Other, Vector HitLocation)
{
	if ( !bActive )
		return;
	// Don't let it hit this player, or blow up on another player
    if ( Other == none || Other == Instigator || Other.Base == Instigator )
		return;

    // Don't collide with bullet whip attachments
    if( KFBulletWhipAttachment(Other) != none )
    {
        return;
    }

    if( Instigator != none )
    {
        OrigLoc = Instigator.Location;
    }
	
	if ( Monster(Other) != none )
	{
		Other.TakeDamage(Damage, Instigator, HitLocation, VRand()*0.0, MyDamageType);
		return;
	}
	
	if ( KFHumanPawn(Other) != none )
	{
		Other.TakeDamage(Damage, Instigator, HitLocation, VRand()*0.0, MyDamageType);
		Deactivate(KFHumanPawn(Other));
	}
}

simulated function Tick( float DeltaTime )
{
	if ( !bActive )
		return;

    SetRotation(Rotator(Normal(Velocity)));

    if( !bOutOfPropellant )
    {
        if ( TotalFlightTime <= StraightFlightTime )
        {
            TotalFlightTime += DeltaTime;
        }
        else
        {
            OuttaPropLocation = Location;
            bOutOfPropellant = true;
        }
    }

    if(  bOutOfPropellant && Physics != PHYS_Falling )
    {
         SetPhysics(PHYS_Falling);
    }

}

simulated function Landed( vector HitNormal )
{
    Deactivate(none);
}

simulated function Deactivate(KFHumanPawn Victim)
{
	StopAnimating();
	SetPhysics(PHYS_None);
	bActive = false;

	if ( Victim != none )
	{
		Stick(Victim);
		lifespan = SlowDuration+0.50;
	}
	else
	{
		lifespan = 30.0;
	}
}

simulated function Stick(KFHumanPawn HitActor)
{
	local name NearestBone;
	local float dist;
	
	Destroy();
	return;

	StuckTo=HitActor;
//	StuckTo.BoostSpeedModifier *= ReduceSpeedTo;

	NearestBone = GetClosestBone(Self.Location, Self.Location, dist , 'CHR_Spine2' , 15 );
	HitActor.AttachToBone(Self,NearestBone);
	
	SetTimer(SlowDuration,false);
}

simulated function Timer()
{
	if ( StuckTo.health > 0 && StuckTo != none )
	{
//		StuckTo.BoostSpeedModifier /= ReduceSpeedTo;
	}
}

defaultproperties
{
     StraightFlightTime=0.75
     AmbientVolumeScale=5.000000
     Speed=2000.000000
     MaxSpeed=2000.000000
     Damage=53.0
     DamageRadius=0.0
     MomentumTransfer=75000.000000
     MyDamageType=Class'DamTypeJasonMacheteRanged'
     ExplosionDecal=none
     DrawType=DT_Mesh
     bUpdateSimulatedPosition=True
     LifeSpan=10.000000
     bUnlit=False
     SoundVolume=255
     SoundRadius=250.000000
     TransientSoundVolume=2.000000
     TransientSoundRadius=500.000000
     bNetNotify=True
     bBlockHitPointTraces=False
     ForceRadius=300.000000
     ForceScale=10.000000
	 Mesh = SkeletalMesh'msmon_01.JasonDTMachete'
	 ReduceSpeedTo = 0.70
	 SlowDuration = 6.0
}
